﻿ 
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using NTTDATA.BEENChina.ResultCertification.model;

namespace NTTDATA.BEENChina.ResultCertification.DataStore
{
    public class JaCityClientAccess: IJaCityClientAccess
    {

        private static string ConnectionString
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["ResultCertificationDB"];
            }
        }
        public List<JaCityItem> GetJaCitys()
        {
            string sql = "SELECT [ID],[Name],[ParentID],[Type],[ShiteiToshi] FROM [JaCity]";


            List<JaCityItem> cityItems = null;
            try
            {
                using (
                    SqlDataReader reader = SqlHelper.ExecuteReader(ConnectionString, System.Data.CommandType.Text, sql))
                {
                    while (reader.Read())
                    {
                        if (cityItems == null)
                            cityItems = new List<JaCityItem>();

                      
                        cityItems.Add( new JaCityItem()
                                           {
                                               ID = reader["ID"].ToString(),
                                               Name = reader["Name"].ToString(),
                                               ParentID = reader["ParentID"].ToString(),
                                               Type = reader["Type"].ToString(),
                                               ShiteiToshi = reader["ShiteiToshi"].ToString()
                                           });
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                Log.Console.Error("JaCityClientAccess.GetJaCitys", ex);
            }

            return cityItems;
        }

        public List<JaMansionItem> GetJaMansions()
        {
            string sql = "SELECT  [ID], [Name], [maxSimilarity]  FROM  [JaMansion] ";


            List<JaMansionItem> mansionItems = null;
            try
            {
                using (
                    SqlDataReader reader = SqlHelper.ExecuteReader(ConnectionString, System.Data.CommandType.Text, sql))
                {
                    while (reader.Read())
                    {
                        if (mansionItems == null)
                            mansionItems = new List<JaMansionItem>();


                        mansionItems.Add(new JaMansionItem()
                        {
                            ID = reader.GetString(0),
                            Name = reader.GetString(1),
                            MaxSimilarity = reader.GetDecimal(2)
                        });
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                Log.Console.Error("JaCityClientAccess.GetJaMansions", ex);
            }

            return mansionItems;
        }
    }
}
